home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS X / Pantomime / Source / strfcpy.c / strfcpy.c
Encoding:
C/C++ Source or Header  |  2002-07-05  |  2.2 KB  |  88 lines

  1. /*******************************************************************************
  2.  *  The Elm Mail System  -  $Revision: 1.2 $   $State: Exp $
  3.  *
  4.  *                      Copyright (c) 1988-1995 USENET Community Trust
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *      Bill Pemberton, Elm Coordinator
  9.  *      flash@virginia.edu
  10.  *
  11.  *******************************************************************************
  12.  * $Log: strfcpy.c,v $
  13.  * Revision 1.2  2002/07/05 14:31:12  ludo
  14.  * see changelog
  15.  *
  16.  * Revision 1.1.1.1  2001/11/21 18:25:35  ludo
  17.  * Imported Sources
  18.  *
  19.  * Revision 1.2  2001/11/18 23:10:25  ludo
  20.  * See ChangeLog
  21.  *
  22.  * Revision 1.1.1.1  2001/09/28 13:06:56  ludo
  23.  * Import of sources
  24.  *
  25.  * Revision 1.1.1.1  2001/07/28 00:06:35  ludovic
  26.  * Imported Sources
  27.  *
  28.  * Revision 1.4  1995/09/29  17:41:39  wfp5p
  29.  * Alpha 8 (Chip's big changes)
  30.  *
  31.  * Revision 1.3  1995/09/11  15:18:59  wfp5p
  32.  * Alpha 7
  33.  *
  34.  * Revision 1.2  1995/05/10  13:34:41  wfp5p
  35.  * Added mailing list stuff by Paul Close <pdc@sgi.com>
  36.  *
  37.  * Revision 1.1.1.1  1995/04/19  20:38:33  wfp5p
  38.  * Initial import of elm 2.4 PL0 as base for elm 2.5.
  39.  *
  40.  ******************************************************************************/
  41.  
  42. #include <Pantomime/elm_defs.h>
  43.  
  44.  
  45. /*
  46.  * This is like strncpy() except the result is guaranteed to be '\0' terminated.
  47.  */
  48. char *strfcpy(dest, src, len)
  49. register char *dest;
  50. register const char *src;
  51. register int len;
  52. {
  53.     (void) strncpy(dest, src, len);
  54.     dest[len-1] = '\0';
  55.     return dest;
  56. }
  57.  
  58.  
  59.  /*
  60.   * differs from strncat in the following ways:
  61.   *   Takes 'len' as the max size of dest, not the bytes to copy.
  62.   *   Doesn't copy whitespace from front and end of src.
  63.   *   The result is guaranteed to be '\0' terminated.
  64.   *   A comma is appended to dest.
  65.   */
  66. void  strfcat(dest, src, len)
  67. char *dest;
  68. const char *src;
  69. int len;
  70.  {
  71.      len -= 3;
  72.      while (*dest++)
  73.      len--;
  74.      if (len <= 0)
  75.      return;
  76.      dest--;
  77.      while (*src == ' ' || *src == '\t')
  78.      src++;
  79.      while (--len > 0 && *src)
  80.      *dest++ = *src++;
  81.      dest--;
  82.      while (*dest == ' ' || *dest == '\t' || *dest == '\n' || *dest == ',')
  83.      dest--;
  84.      *++dest = ',';
  85.      *++dest = ' ';
  86.      *++dest = '\0';
  87.  }
  88.